package cz.muni.fi.pa165.library.backend;

import cz.muni.fi.pa165.library.api.UserService;
import java.io.IOException;
import javax.security.auth.callback.Callback;
import javax.security.auth.callback.CallbackHandler;
import javax.security.auth.callback.UnsupportedCallbackException;
import org.apache.ws.security.WSPasswordCallback;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

@Component
public class ServerPasswordCallback implements CallbackHandler {
   
    @Autowired
    private UserService userService;

    @Override
    public void handle( Callback[] callbacks ) throws IOException, UnsupportedCallbackException {

        WSPasswordCallback pc = (WSPasswordCallback) callbacks[0];

        pc.setPassword(userService.findUserByEmail(pc.getIdentifier()).getPassword());
    }

}

